package com.wondersgroup.fjzlpt.yyzyzx.service.impl.yyzycx;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.util.ExcelOrWordUtils;
import com.wondersgroup.fjzlpt.yyzyzx.dao.inter.yyzycx.CwxxDAO;
import com.wondersgroup.fjzlpt.yyzyzx.service.inter.yyzycx.CwxxService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 床位信息查询实现层
 * <p>
 * <p>
 * Created by sanma on 2017/8/7.
 */
@Service
public class CwxxServiceImpl  implements CwxxService{

    @Autowired
    private CwxxDAO cwxxDAO;

    @Override
    public JSONObject pageQueryCwxxAll(Map map) {
        return cwxxDAO.pageQueryCwxxAll(map);
    }

    /**
     * 查询所有数据并导出到Excel
     * @param map
     * @return
     */
	@Override
	public void queryAllForExcel(Map map, HttpServletRequest request, HttpServletResponse response) {
		JSONArray downData = cwxxDAO.queryAllOnView(map);
		
		//表头
		StringBuffer titleStr = new StringBuffer();
		titleStr.append("{'YLJGMC':'医院名称','YYJBMC':'医院等级','KSMC':'科室名称','BQMC':'病区名称','SJKFCWS':'实际开放床位数','DQKCS':'当前床位数',")
				.append("'DDCWS':'已预约床位数','DQKYYCWS':'可预约床位数','CWSYL':'床位使用率'}");
		JSONObject title = JSONObject.parseObject(titleStr.toString());
		downData.add(0, title);
		
		//排列循序
		List<String> titelField = new ArrayList<>();
		titelField.add("YLJGMC");
		titelField.add("YYJBMC");
		titelField.add("KSMC");
		titelField.add("BQMC");
		titelField.add("SJKFCWS");
		titelField.add("DQKCS");
		titelField.add("DDCWS");
		titelField.add("DQKYYCWS");
		titelField.add("CWSYL");
		ExcelOrWordUtils.downLoadExcelFile(downData, titelField ,"实时床位列表",request, response);
		
	}
}
